<template>
  <div>
    <!-- 面包屑导航 -->
    <el-breadcrumb separator-class="el-icon-arrow-right">
      <el-breadcrumb-item :to="{ path: '/operationsummary/Operations' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>库存管理</el-breadcrumb-item>
    </el-breadcrumb>
    <br />
    <br />
    <!-- 页面上方的分标签页 -->
    <el-tabs v-model="activeName" type="card" @tab-click="handleTabClick">
      <el-tab-pane label="库存记录" name="first">
        <!-- 库存记录查询组件 -->
        <StockLog :employeeDict="employeeDict" />
      </el-tab-pane>
      <el-tab-pane label="库存明细" name="sixth">
        <!-- 库存明细组件 -->
        <StockDetail :employeeDict="employeeDict" />
      </el-tab-pane>
      <el-tab-pane label="采购入库" name="second">
        <!-- 药品入库组件 -->
        <StockNew
          operType="2"
          :recordNo="this.recordNo"
          :employeeDict="employeeDict"
        />
      </el-tab-pane>
      <el-tab-pane label="处方出库" name="third">
        <!-- 处方出库组件 -->
        <StockNew
          operType="4"
          :recordNo="this.recordNo"
          :employeeDict="employeeDict"
        />
      </el-tab-pane>
      <el-tab-pane label="退货出库" name="fourth">
        <!-- 药品退货组件 -->
        <StockNew
          operType="1"
          :recordNo="this.recordNo"
          :employeeDict="employeeDict"
        />
      </el-tab-pane>
      <el-tab-pane label="库存盘点" name="fifth">
        <!-- 药品退货组件 -->
        <StockNew
          operType="3"
          :recordNo="this.recordNo"
          :employeeDict="employeeDict"
        />
      </el-tab-pane>
    </el-tabs>
  </div>
</template>


<script>
// 导入组件
import StockLog from "./StockLog.vue";
import StockNew from "./StockNew.vue";
import StockDetail from "./StockDetail.vue";
// 引入 moment
import moment from "moment";
import axios from "axios";

export default {
  // 导入的组件写到这里
  components: { StockLog, StockNew, StockDetail },

  data() {
    return {
      // 默认选中的组件
      activeName: "first",
      // 员工字典
      employeeDict: {},
      recordNo: "",
    };
  },
  created() {
    this.getemployeeDict();
  },
  methods: {
    getemployeeDict() {
      axios
        .post("/api/employee/selectAllEmployee?pageNum=1&pageSize=100", {})
        .then((res) => {
          for (let item of res.data.data.list) {
            this.employeeDict[item.id] = item.name;
          }
        })
        .catch((err) => {
          this.editFormVisible = false;
          this.loading = false;
          this.$message.error("获取员工数据失败，请稍后再试！");
        });
    },
    handleTabClick(param) {
      let num =
        moment().format("YYYYMMDDHHmmss") + Math.floor(Math.random() * 10);
      switch (param.index) {
        case "2":
          this.recordNo = "SP" + num;
          break;
        case "3":
          this.recordNo = "CO" + num;
          break;
        case "4":
          this.recordNo = "CB" + num;
          break;
        case "5":
          this.recordNo = "SA" + num;
          break;
      }
    },
  },
};
</script>